﻿#include <iostream>
using namespace std;
int mod(int k, int e, int m)
{
    int result = 1;
    m = m % k;
    while (e > 0)
    {
        if (e % 2 == 1)
        {
            result = (result * m) % k;
        }
        m = (m * m) % k;
        e = e / 2;
    }
    return result;
}
int main()
{
    int p, q, e, m;
    cin >> p >> q >> e >> m;
    int k = p * q;
    int result = mod(k, e, m);
    cout << result << endl;
    return 0;
}

